package itbour.onetouchshow.activity.challengezone.video;

import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;
import com.lsjr.callback.EncryBeanCallBack;
import com.lsjr.utils.HttpUtils;

import java.util.HashMap;

import itbour.onetouchshow.base.mvp.BasePresenterImpl;
import itbour.onetouchshow.bean.BasePageData;
import itbour.onetouchshow.constants.AppConfig;
import itbour.onetouchshow.constants.AppConst;

/**
 * Created by guoh on 2018/7/6.
 * 功能描述：
 * 需要的参数：
 */
public class MusicListPresenter extends BasePresenterImpl<MusicListView> {

    private int pageNum = 0;

    public void getMusicList(boolean loadMore) {
        if (loadMore) {
            pageNum += 1;
        }
        HashMap<String, Object> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringStringHashMap.put("pageNum", pageNum);
        stringStringHashMap.put("pageSize", 16);
        stringStringHashMap.put("withTotalPage", 1);

        Log.e("stringStringHashMap", new Gson().toJson(stringStringHashMap));

        HttpUtils.getInstance().executeGet(AppConfig.GET_BGM_LIST, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                if (mvpView != null) {
                    mvpView.loadMusicListFail(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                if (mvpView != null) {
                    if (!TextUtils.isEmpty(response)) {
                        BasePageData pageData = new Gson().fromJson(response, BasePageData.class);
                        mvpView.loadMusicListSuccess(pageData, loadMore);
                    }
                }
            }
        });
    }
}
